<template>
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item label="订单编号" prop="dictName">
                <el-input v-model="queryParams.orderNum" placeholder="请输入订单编号" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="联系人" prop="dictName">
                <el-input v-model="queryParams.linkName" placeholder="请输入联系人姓名" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="联系电话" prop="dictName">
                <el-input v-model="queryParams.linkTel" placeholder="请输入联系电话" clearable style="width: 240px"
                    @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                    v-hasPermi="['order:order:add']">下单</el-button>
            </el-col>

            <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="OrderList">
            <el-table-column label="社区id" align="center" prop="deptId" />
            <el-table-column label="订单编号" align="center" prop="orderNum" />
            <el-table-column label="联系人" align="center" prop="linkName" />
            <el-table-column label="联系电话" align="center" prop="linkTel" />
            <el-table-column label="上门服务地址" align="center" prop="address" />
            <el-table-column label="上门服务时间" align="center" prop="serverTime" />
            <el-table-column label="下单人" align="center" prop="ordererId" />
            <el-table-column label="接单人" align="center" prop="takerId" />
            <el-table-column label="状态" align="center" prop="status">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_status" :value="scope.row.status" />
                </template>
            </el-table-column>
            <el-table-column label="服务类型" align="center" prop="type">
                <template slot-scope="scope">
                    <dict-tag :options="dict.type.sys_type" :value="scope.row.type" />
                </template>
            </el-table-column>

            <el-table-column label="服务详情" align="center" prop="concent" />
            <el-table-column label="创建者" align="center" prop="createBy" />
            <el-table-column label="创建时间" align="center" prop="createTime" width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.createTime) }}</span>
                </template>
            </el-table-column>
            <el-table-column label="更新者" align="center" prop="updateBy" />
            <el-table-column label="更新时间" align="center" prop="updateTime" />
            <el-table-column label="备注" align="center" prop="remark" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handlereceive(scope.row)"
                        v-hasPermi="['order:order:receive']">接单</el-button>
                    <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
                        v-hasPermi="['order:order:edit']">修改</el-button>
                    <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
                        v-hasPermi="['order:order:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
        <!-- 添加参数配置对话框 -->
        <el-dialog :title="title" :visible.sync="dialogVisible" width="500px">
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="社区id">
                    <el-input v-model="form.deptId" />
                </el-form-item>
                <el-form-item label="订单编号">
                    <el-input v-model="form.orderNum" placeholder="请输入订单编号" />
                </el-form-item>
                <el-form-item label="联系人">
                    <el-input v-model="form.linkName" />
                </el-form-item>
                <el-form-item label="联系电话">
                    <el-input v-model="form.linkTel" />
                </el-form-item>
                <el-form-item label="上门服务地址">
                    <el-input v-model="form.address" />
                </el-form-item>
                <el-form-item label="上门服务时间">

                    <el-date-picker v-model="form.serverTime" type="datetime" placeholder="选择日期时间" align="right"
                        value-format="yyyy-MM-dd HH:mm:ss" :picker-options="pickerOptions">
                    </el-date-picker>

                </el-form-item>
                <el-form-item label="下单人">
                    <el-input v-model="form.ordererId" />
                </el-form-item>
                <el-form-item label="接单人">
                    <el-input v-model="form.takerId" />
                </el-form-item>
                <el-form-item label="订单状态">
                    <el-input v-model="form.status" />
                    <template slot-scope="scope">
                        <dict-tag :options="dict.type.sys_status" :value="scope.row.status" />
                    </template>

                </el-form-item>
                <el-form-item label="服务类型">
                    <el-select v-model="form.type" >
                        <el-option v-for="dict in dict.type.sys_type" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>



                <el-form-item label="服务详情">
                    <el-input v-model="form.content" />
                </el-form-item>
                <el-form-item label="备注">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>
        <!-- 修改参数配置对话框 -->
        <el-dialog :title="title" :visible.sync="open" width="500px">
            <el-form ref="form" :model="form" label-width="80px">
                <el-form-item label="社区id">
                    <el-input v-model="form.deptId" />
                </el-form-item>
                <el-form-item label="联系人">
                    <el-input v-model="form.linkName" />
                </el-form-item>
                <el-form-item label="联系电话">
                    <el-input v-model="form.linkTel" />
                </el-form-item>
                <el-form-item label="上门服务地址">
                    <el-input v-model="form.address" />
                </el-form-item>
                <el-form-item label="上门服务时间">
                    <el-date-picker v-model="form.serverTime" type="datetime" placeholder="选择日期时间" align="right"
                        value-format="yyyy-MM-dd HH:mm:ss" :picker-options="pickerOptions">
                    </el-date-picker>
                </el-form-item>

                <el-form-item label="服务类型">
                    <el-select v-model="form.type">
                        <el-option v-for="dict in dict.type.sys_type" :key="dict.value" :label="dict.label"
                            :value="dict.value"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="备注">
                    <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitForm">确 定</el-button>
                <el-button @click="cancel">取 消</el-button>
            </div>
        </el-dialog>

    </div>
</template>
<script>
import { selectOrder, addOrder, editOrder, deleteOrder, receiveOrder } from "@/api/order/order";
import dict from "../../store/modules/dict";
import { status } from "nprogress";
export default {
    name: "Order",
    dicts: ["sys_status", "sys_type"],
    data() {
        return {
            value: '',
            //显示搜索条件
            showSearch: true,
            // 遮罩层
            loading: true,
            //总条数
            total: 0,
            // 选中数组
            ids: [],
            //查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                userName: undefined,
                userId: undefined
            },
            //新增属性
            title: "",
            dialogVisible: false,
            form: {
                id: undefined,
                deptId: undefined,
                orderNum: undefined,
                linkName: undefined,
                linkTel: undefined,
                address: undefined,
                serverTime: undefined,
                ordererId: undefined,
                takerId: undefined,
                type: undefined,
                content: undefined,
                remark: undefined,
            },
            //修改属性
            open: false,

            OrderList: [],
            // 表单校验
            rules: {

            },
            /////
            pickerOptions: {
                shortcuts: [{
                    text: '今天',
                    onClick(picker) {
                        picker.$emit('pick', new Date());
                    }
                }, {
                    text: '昨天',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24);
                        picker.$emit('pick', date);
                    }
                }, {
                    text: '一周前',
                    onClick(picker) {
                        const date = new Date();
                        date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
                        picker.$emit('pick', date);
                    }
                }]
            },
        }
    },
    created() {
        this.getList();

    },
    methods: {
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },


        /** 重置按钮操作 */
        resetQuery() {
            this.queryParams = {
                pageNum: 1,
                pageSize: 10,
                userName: undefined,
                userId: undefined,
            },
                this.resetForm("queryForm");
            this.handleQuery();
        },
        /** 查询信息 */
        getList() {
            selectOrder(this.queryParams).then(response => {
                this.OrderList = response.rows;
                this.total = response.total;
                this.loading = false;
            }
            );

        },
        /** 新增按钮操作 */
        handleAdd() {
            this.reset();
            this.dialogVisible = true;
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            this.reset();
            this.open = true;
            this.form = row;
        },

        handlereceive: function (row) {
            const id = row.id;
            const status = row.status;
            if (id != undefined && status == 0) {
                receiveOrder(row);
                this.$modal.msgSuccess("接单成功");
                this.getList();
            }
        },
        // 取消按钮
        cancel() {
            this.dialogVisible = false;
            this.open = false;
            this.reset();
        },
        /** 提交按钮 */
        submitForm: function () {
            this.$refs["form"].validate(valid => {
                if (valid) {
                    if (this.form.id != undefined) {
                        editOrder(this.form).then(response => {
                            this.$modal.msgSuccess("修改成功");
                            this.open = false;
                            this.getList();
                        });
                    }
                    else {
                        addOrder(this.form).then(response => {
                            this.$modal.msgSuccess("新增成功");
                            this.dialogVisible = false;
                            this.getList();
                        });
                    }
                }
            });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            console.log(row)
            const id = row.id;
            this.$modal.confirm('是否确认删除用户为"' + id + '"的数据项？').then(function () {
                return deleteOrder(id);
            }).then(() => {
                this.getList();
                this.$modal.msgSuccess("删除成功");
            }).catch(() => { });
        },
        reset() {
            this.form = {
                id: undefined,
                deptId: undefined,
                orderNum: undefined,
                linkName: undefined,
                linkTel: undefined,
                address: undefined,
                serverTime: undefined,
                ordererId: undefined,
                takerId: undefined,
                status: undefined,
                type: undefined,
                content: undefined,
                remark: undefined,
            };
            this.resetForm("form");
        },



    }
};
</script>
<style scoped></style>